package com.neusoft.elmboot.controller;

import java.util.List;

import com.neusoft.elmboot.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.neusoft.elmboot.po.DeliveryAddress;
import com.neusoft.elmboot.service.DeliveryAddressService;

/**
 * 地址
 * Controller
 */
@RestController
@Slf4j
@RequestMapping("/DeliveryAddressController")
public class DeliveryAddressController {
    @Autowired
    private DeliveryAddressService deliveryAddressService;

    @RequestMapping(value = "/listDeliveryAddressByUserId")
    public Result<List<DeliveryAddress>> listDeliveryAddressByUserId(DeliveryAddress deliveryAddress)
            throws Exception{
        log.info("调用接口：根据用户ID查询地址");
        return Result.success(deliveryAddressService.listDeliveryAddressByUserId(deliveryAddress.getUserId()));
    }

    @RequestMapping(value = "/getDeliveryAddressById")
    public Result<DeliveryAddress> getDeliveryAddressById(DeliveryAddress deliveryAddress) throws
            Exception{
        log.info("调用接口：根据地址ID查询地址信息");
        return Result.success(deliveryAddressService.getDeliveryAddressById(deliveryAddress.getDaId()));
    }

    @RequestMapping(value = "/saveDeliveryAddress")
    public Result<Integer> saveDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
        log.info("调用接口：新增地址信息");
        return Result.success(deliveryAddressService.saveDeliveryAddress(deliveryAddress));
    }

    @RequestMapping(value = "/updateDeliveryAddress")
    public Result<Integer> updateDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
        log.info("调用接口：更新地址信息");
        return Result.success(deliveryAddressService.updateDeliveryAddress(deliveryAddress));
    }

    @RequestMapping(value = "/removeDeliveryAddress")
    public Result<Integer> removeDeliveryAddress(DeliveryAddress deliveryAddress) throws Exception{
        log.info("调用接口：删除地址信息");
        return Result.success(deliveryAddressService.removeDeliveryAddress(deliveryAddress.getDaId()));
    }
}
